package ${package.ServiceImpl};

import ${package.Mapper}.${table.mapperName};
<#if generateService>
import ${package.Service}.${table.serviceName};
</#if>
import ${superServiceImplClassPackage};
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wulis.common.converter.MapperConvert;
import ${package.Entity}.entity.${entity};
import ${package.Entity}.request.${entity}DeleteReq;
import ${package.Entity}.request.${entity}InsertReq;
import ${package.Entity}.request.${entity}PageReq;
import ${package.Entity}.request.${entity}UpdateReq;
import ${package.Entity}.response.${entity}InfoRes;
import ${package.Entity}.response.${entity}PageRes;
import org.springframework.stereotype.Service;
import com.wulis.common.utils.PageUtil;

/**
 * Service Implements
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<#if generateService>, ${table.serviceName}</#if> {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><#if generateService> implements ${table.serviceName}</#if> {

    /**
     * 分页
     *
     * @param pageReq pageReq
     * @return PageResult
     */
    @Override
    public IPage<${entity}PageRes> page(${entity}PageReq pageReq) {
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        IPage<${entity}> page = baseMapper.selectPage(Page.of(pageReq.getPageNumber(), pageReq.getPageSize()), queryWrapper);
        return PageUtil.convert(page, ${entity}PageRes.class);
    }

    /**
     * 详情
     *
     * @param id id
     * @return ${entity}Detail
     */
    @Override
    public ${entity}InfoRes getInfo(Long id) {
        ${entity} ${entity?substring(0,1)?lower_case}${entity?substring(1)} = baseMapper.selectById(id);
        return MapperConvert.map(${entity?substring(0,1)?lower_case}${entity?substring(1)}, ${entity}InfoRes.class);
    }

    /**
     * 新增
     *
     * @param insertReq insertReq
     */
    @Override
    public void insert(${entity}InsertReq insertReq) {
        ${entity} ${entity?substring(0,1)?lower_case}${entity?substring(1)} = MapperConvert.map(insertReq, ${entity}.class);
        baseMapper.insert(${entity?substring(0,1)?lower_case}${entity?substring(1)});
    }

    /**
     * 修改
     *
     * @param updateReq updateReq
     */
    @Override
    public void update(${entity}UpdateReq updateReq) {
        ${entity} ${entity?substring(0,1)?lower_case}${entity?substring(1)} = MapperConvert.map(updateReq, ${entity}.class);
        baseMapper.updateById(${entity?substring(0,1)?lower_case}${entity?substring(1)});
    }

    /**
     * 删除
     *
     * @param deleteReq deleteReq
     */
    @Override
    public void delete(${entity}DeleteReq deleteReq) {
        baseMapper.deleteById(deleteReq.getId());
    }
}
</#if>
